<template>
  <div id="home">
    <el-container class="home-container">
      <el-header height="60px">
        <h1>zxum管理控制台</h1>
        <div class="zwf"></div>
        <div class="user-info">

          <el-menu mode="horizontal" :default-active="$route.path" text-color="#fff" active-text-color="#ffd04b" background-color="#505255" @select="handleSelect" router>
            <el-submenu index="1">
              <template slot="title">{{loginUser}}</template>
              <el-menu-item index="/login">
                退出
              </el-menu-item>
            </el-submenu>
          </el-menu>
          <!-- <div>||</div> -->
          <div>
            <a href="#" style="font-size: 14px;line-height:60px">{{roleName}} </a>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="252px">
          <el-menu :default-openeds="[activeIndex]"  @select="selectMenu" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
            <label v-for="(item,index) in leftMenus" :key="index">
              <el-submenu :index="String(item.id)">
                <template slot="title">
                  <i class="el-icon-location"></i>{{item.label}}</template>
                <el-menu-item-group v-for="(tt,tindex) in item.menus" :key="tindex">
                  <router-link :to="{path:tt.path}">
                    <el-menu-item :index="String(tt.id)">
                      {{tt.label}}
                    </el-menu-item>
                  </router-link>
                </el-menu-item-group>
              </el-submenu>
            </label>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
    data() {
        return {
            loginUser: "",
            roleName: "",
            leftMenus: [],
            activeIndex: "1"
        };
    },
    methods: {
       selectMenu(index, indexPath){
          if(indexPath.length>1){
            this.activeIndex=indexPath[0];
          }
         
       },
        initLeftMenu() {
            let _this = this;
            this.$http
                .post("/role/menuIsList")
                .then(res => {
                    if (res.status == 200) {
                        this.leftMenus = res.data.data;
                        //this.$store.commit('setMenuList',res.data.data)
                        //_this.treeData = res.data.data;
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        handleSelect() {}
    },
    mounted() {
        this.loginUser = this.$store.state.username || sessionStorage.getItem("username");
        this.roleName=this.$store.state.roleName || sessionStorage.getItem("roleName");
        this.initLeftMenu();
        // console.log(this.$route.path);
    }
};
</script>

<style scoped>
.el-menu-vertical-demo {
    display: inline-block;
    text-align: left;
    height: 100%;
    width: 240px;
}
a {
    text-decoration: none;
}

/* .el-menu--horizontal >>> .el-submenu a{
  color: #fff;
}  */
/* .el-submenu .el-menu-item{
  width: auto;
  background-color: #fff;
} */

.home-container {
    height: 100%;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
}
.el-header {
    background-color: rgb(80, 82, 85);
    color: #fff;
    height: 60px;
    padding-bottom: 16px;
    line-height: 1;
    display: flex;
}
.zwf {
    flex: 1;
}
.user-info {
    width: 256px;
    display: flex;
    height: 56px;
    flex: 0 0 156px;
}
.user-info a {
    color: #fff;
}
.user-info > div {
    width: 100px;
    line-height: 56px;
    margin-left: 10px;
}
.el-submenu .el-menu-item {
    z-index: 99;
}
.el-main {
    background-color: #ffffff;
    /* text-align: center; */
    /* background-color: #e9eef3;
    text-align: center;
    margin: 0 auto; */
}

body > .el-container {
    margin-bottom: 40px;
    text-align: center;
}
</style>

